﻿#include "Belt.h"
#include "CBeltSqlOper.h"
#include "UBeltConfig.h"
#include "ULogInfoPane.h"
#include "UMainUi.h"
Belt::Belt()
{
}

Belt::Belt(QString sName, QString sId, QString sConfig)
{
	m_sName = sName;
	m_sId = sId;
	m_nType = 0;
	m_pConfoig = nullptr;
	init();
}

Belt::~Belt()
{
	if (m_pPointMgrBase != nullptr)
	{
		delete m_pPointMgrBase;
		m_pPointMgrBase = nullptr;
	}
}

bool Belt::startDevice()
{
	/**
	* @ Author: Gaojia
	* @ Description: 启动测点数据刷新
	*/
	m_pPointMgrBase->start();
	/**
	* @ Author: Gaojia
	* @ Description: 设备开始工作
	*/
	//......................
	return true;
}

bool Belt::stopDevice()
{
	/**
	* @ Author: Gaojia
	* @ Description: 停止测点数据刷新
	*/
	m_pPointMgrBase->stop();
	/**
	* @ Author: Gaojia
	* @ Description: 设备停止工作
	*/
	//......................
	return false;
}

QWidget * Belt::getDeviceConfigUi()
{
	if (m_pConfoig == nullptr)
	{
		m_pConfoig = new UBeltConfig(m_pBeltData);
	}
	return m_pConfoig;
}

QWidget * Belt::getMainUi()
{
	m_pMainUi = new UMainUi();
	((UMainUi*)m_pMainUi)->initUI(m_pBeltData);
	return m_pMainUi;
}

QWidget * Belt::getPanel(int nId)
{
	return m_pBeltFactHy->getPanel(nId);
}

QVector<QWidget*> Belt::getPanelList()
{
	return m_pBeltFactHy->getPanelList();
}

QList<CMeasurePoint*> Belt::getMeasurePoints()
{
	return m_pPointMgrBase->getPoint();
}

QMap<QString, QString> Belt::getInputPointList()
{
	return m_mapPointList;
}

void Belt::setInputPoint(QMap<QString, CMeasurePoint*>mapPoint)
{
	m_mapInputPoint = mapPoint;
	m_pBeltData->m_mapInputPoint = mapPoint;
}

void Belt::init()
{
	QString sErr = "";
	m_sGuid = selectDeviceInfo(m_sId, m_nType, sErr);
	//selectPoint(m_sGuid, m_mapPointList);
	/**
	* @ Author: Gaojia
	* @ Description: 创建设备
	*/
	switch (m_nType)
	{
	case 0:
		m_pBeltFactHy = new CBeltFactHy(m_sGuid, m_sName);
		m_pBeltFactHy->createAll(this);
		break;
	default:
		break;
	}
}
